<template>
	<div class="game-container report-container">
		<el-tabs v-model="activeName" @tab-click="initData">
			<el-tab-pane
				:label="$t('funds.fund_audit.platform_deposit_records')"
				name="0"
			>
				<main-content
					classType="wrapInner"
					:tableHeight.sync="topProxyTableHeight"
					:otherDependenComponents="otherDependenComponents"
				>
					<template slot="query">
						<ProxySearch
							:tabSign="tabSign"
							:defaultCycleTime="defaultCycleTime"
							:defaultPayoutTime="defaultPayoutTime"
							:searchLoading="searchLoading"
							:exportLoading="exportLoading"
							@handleSearch="handleSearch"
							@handleReset="handleReset"
							@handleExport="handleExport"
							@openColSettings="openColSettings"
						></ProxySearch>
					</template>
					<template slot="content">
						<PlatformDepositRecords
							:tableHeight="topProxyTableHeight"
							:searchLoading="searchLoading"
							:tableData="tableData"
							:subSummary="subSummary"
							:totalSummary="totalSummary"
							:allPayoutStatus="commissionPayoutStatus"
							:activityList="activityListTopField"
							:key="tabRandom"
						></PlatformDepositRecords>
						<!-- 分页 -->
						<el-pagination
							v-show="!!total"
							:current-page.sync="pageNum"
							class="pageValue"
							background
							layout="total, sizes,prev, pager, next, jumper"
							:page-size="pageSize"
							:page-sizes="pageSizes"
							:total="total"
							:pager-count="9"
							@current-change="handleCurrentChange"
							@size-change="handleSizeChange"
						></el-pagination>
					</template>
				</main-content>
			</el-tab-pane>
			<el-tab-pane
				:label="$t('funds.fund_audit.platform_withdrawal_records')"
				name="1"
			>
				<main-content
					v-if="activeName === '1'"
					classType="wrapInner"
					:tableHeight.sync="nonTopProxyTableHeight"
					:otherDependenComponents="otherDependenComponents"
				>
					<template slot="query">
						<ProxySearch
							:tabSign="tabSign"
							:defaultCycleTime="defaultCycleTime"
							:defaultPayoutTime="defaultPayoutTime"
							:searchLoading="searchLoading"
							:exportLoading="exportLoading"
							@handleSearch="handleSearch"
							@handleReset="handleReset"
							@handleExport="handleExport"
							@openColSettings="openColSettings"
						></ProxySearch>
					</template>
					<template slot="content">
						<PlatformWithdrawalRecords
							:tableHeight="nonTopProxyTableHeight"
							:searchLoading="searchLoading"
							:tableData="tableData"
							:allPayoutStatus="commissionPayoutStatus"
							:subSummary="subSummary"
							:totalSummary="totalSummary"
							:activityList="activityListNotTopField"
							:key="tabRandom"
						></PlatformWithdrawalRecords>
						<!-- 分页 -->
						<el-pagination
							v-show="!!total"
							:current-page.sync="pageNum"
							class="pageValue"
							background
							layout="total, sizes,prev, pager, next, jumper"
							:page-size="pageSize"
							:page-sizes="pageSizes"
							:total="total"
							:pager-count="9"
							@current-change="handleCurrentChange"
							@size-change="handleSizeChange"
						></el-pagination>
					</template>
				</main-content>
			</el-tab-pane>
		</el-tabs>
		<!-- 列设置 -->
		<!-- <el-dialog
			:title="$t('common.row_set')"
			center
			:visible.sync="colSettings.visible"
			width="475px"
			class="setting-div"
		>
			<div>
				<el-link type="primary" class="mb15" @click="clickDel">
					复原缺省
				</el-link>
			</div>
			<div
				v-for="(value, name1) in activityListField"
				:key="name1"
				class="setting-div"
			>
				<el-checkbox v-model="dialogColumnData[name1]">
					{{ name1 }}
				</el-checkbox>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button @click="colSettings.visible = false">
					{{ $t('common.cancel') }}
				</el-button>
				<el-button type="primary" @click="handleColSettings">
					{{ $t('common.submit') }}
				</el-button>
			</div>
		</el-dialog> -->
	</div>
</template>

<script>
import list from '@/mixins/list'
import dayjs from 'dayjs'
import { routerNames } from '@/utils/consts'
import { commissionPayoutStatus } from '@/dict/funds'
import ProxySearch from './components/ProxySearch'
import PlatformDepositRecords from './components/PlatformDepositRecords'
import PlatformWithdrawalRecords from './components/PlatformWithdrawalRecords'
import MainContent from '@/components/MainContent/index.vue'
// const end = dayjs().endOf('day')
// const start = dayjs().startOf('day')
const end1 = () => {
	return dayjs().endOf('day')
}
const start1 = () => {
	return dayjs().startOf('day')
}

export default {
	name: routerNames.agentRebateRecord,
	components: {
		ProxySearch,
		PlatformDepositRecords,
		PlatformWithdrawalRecords,
		MainContent
	},
	mixins: [list],
	data() {
		return {
			topProxyTableHeight: 480,
			nonTopProxyTableHeight: 480,
			otherDependenComponents: ['wrap'],
			activeName: '0',
			tabSign: '0',
			tabRandom: 0,
			queryData: {
				inputType2: 1
			},
			tableData: [],
			subSummary: {},
			totalSummary: {},
			searchLoading: false,
			exportLoading: false,
			activityListField: {},
			activeFiledName: '',
			colSettings: {
				visible: false,
				dialogColumnData: {}
			},
			activityListTopField: {
				[this.$t('funds.fund_audit.connect_three_order_no')]: true,
				[this.$t('funds.deposit_account')]: true,
				[this.$t('funds.proxy_member_funds_record.real_name')]: true,
				[this.$t(
					'funds.proxy_member_funds_record.top_proxy_name'
				)]: true,
				[this.$t(
					'funds.proxy_member_funds_record.parent_proxy_name'
				)]: true,
				[this.$t('common.belong_merchant')]: true,
				[this.$t('funds.proxy_member_funds_record.app_type')]: true,
				[this.$t('funds.proxy_member_funds_record.order_status')]: true,
				[this.$t('funds.proxy_member_funds_record.client_state')]: true,
				[this.$t('funds.proxy_member_funds_record.deposit_ip')]: true,
				[this.$t('funds.proxy_member_funds_record.device_no')]: true,
				[this.$t(
					'funds.thirdPeymentChannelConfig.payment_merchant_name'
				)]: true,
				[this.$t('funds.pay_type')]: true,
				[this.$t('funds.fund_audit.pay_currency')]: true,
				[this.$t('funds.channel_name')]: true,
				[this.$t('funds.fund_audit.order_save_money_usdt')]: true,
				[this.$t('funds.fund_audit.order_save_money_cny')]: true,
				[this.$t('funds.fund_audit.real_record_money_usdt')]: true,
				[this.$t('funds.fund_audit.real_record_money_cny')]: true,
				[this.$t('funds.apply_time')]: true,
				[this.$t('funds.proxy_member_funds_record.arrive_time')]: true,
				[this.$t('common.remark')]: true,
				[this.$t('common.number_type')]: true
			},
			activityListNotTopField: {
				[this.$t('common.number_type')]: true,
				[this.$t(
					'funds.proxy_member_funds_record.parent_proxy_name'
				)]: true,
				[this.$t(
					'funds.proxy_member_funds_record.top_proxy_name'
				)]: true,
				[this.$t('funds.fund_audit.connect_three_order_no')]: true,
				[this.$t('funds.bg_name')]: true,
				[this.$t('common.belong_merchant')]: true,
				[this.$t('funds.proxy_member_funds_record.app_type')]: true,
				[this.$t('funds.proxy_member_funds_record.order_status')]: true,
				[this.$t('funds.proxy_member_funds_record.client_state')]: true,
				[this.$t(
					'funds.proxy_member_funds_record.withdrawal_ip'
				)]: true,
				[this.$t(
					'funds.proxy_member_funds_record.withdrawal_terminal_numbe'
				)]: true,
				[this.$t(
					'funds.thirdPeymentChannelConfig.payment_merchant_name'
				)]: true,
				[this.$t('funds.pay_type')]: true,
				[this.$t('funds.fund_audit.pay_currency')]: true,
				[this.$t('funds.channel_name')]: true,
				[this.$t(
					'funds.proxy_member_funds_record.withdraw_account'
				)]: true,
				[this.$t(
					'funds.proxy_member_funds_record.withdraw_info'
				)]: true,
				[this.$t(
					'common.withdraw_money_wallet'
				)]: true,
				[this.$t(
					'funds.proxy_member_funds_record.withdraw_order_amount_usdt'
				)]: true,
				[this.$t(
					'funds.proxy_member_funds_record.withdraw_order_amount_cny'
				)]: true,
				[this.$t(
					'funds.proxy_member_funds_record.first_withdraw_status'
				)]: true,
				[this.$t(
					'funds.proxy_member_funds_record.is_big_withdraw_amount'
				)]: true,
				[this.$t('funds.apply_time')]: true,
				[this.$t(
					'funds.proxy_member_funds_record.paragraph_time'
				)]: true,
				[this.$t('funds.proxy_member_funds_record.audit_desc')]: true,
				[this.$t(
					'funds.proxy_member_funds_record.audit_client_desc'
				)]: true
			},
			commissionPayoutStatus
		}
	},
	computed: {
		defaultCycleTime() {
			return [start1(), end1()]
		},
		defaultPayoutTime() {
			return []
		}
	},
	created() {
		this.setDefaultColSettings()
	},
	mounted() {},
	methods: {
		handleSearch(queryData, num) {
			this.pageNum = 1
			this.queryData = queryData
			this.loadData()
		},
		getSearchParams() {
			const timeCycleArr =
				this.queryData?.searchCycleTime || this.defaultCycleTime
			const timeFlag = this.queryData?.timeFlag || '0'
			const params = {
				...this.queryData,
				eventTimeStart:
					timeFlag === '1'
						? dayjs(timeCycleArr[0]).format('YYYY-MM-DD HH:mm:ss')
						: undefined,
				eventTimeEnd:
					timeFlag === '1'
						? dayjs(timeCycleArr[1]).format('YYYY-MM-DD HH:mm:ss')
						: undefined,
				payTimeStart:
					timeFlag === '0'
						? dayjs(timeCycleArr[0]).format('YYYY-MM-DD HH:mm:ss')
						: undefined,
				payTimeEnd:
					timeFlag === '0'
						? dayjs(timeCycleArr[1]).format('YYYY-MM-DD HH:mm:ss')
						: undefined
			}
			if (params.payoutStatus) {
				if (Number(params.payoutStatus) === 1) {
					params.payoutStatusList = [0, 1, 2]
				} else {
					params.payoutStatusList = [Number(params.payoutStatus)]
				}
				delete params.payoutStatus
			}
			const inputTypeName1 = [
				'topProxyName',
				'parentProxyName',
				'belongProxyName'
			]
			const inputTypeName2 = [
				'topProxyUsername',
				'parentProxyUsername',
				'proxyUsername'
			]
			if (this.tabSign === '0') {
				params[inputTypeName1[params.inputType2]] = params.inputValue2
			} else {
				params[inputTypeName2[params.inputType2]] = params.inputValue2
			}

			// if (params.inputType === 0) {
			// 	params.userName = params.inputValue || undefined
			// } else if (params.inputType === 1) {
			// 	params.realName = params.inputValue || undefined
			// } else if (params.inputType === 1) {
			// 	params.realName = params.inputValue || undefined
			// }
			delete params.inputType2
			delete params.inputValue2
			delete params.searchCycleTime
			delete params.searchPayoutTime
			delete params.timeFlag
			// if (this.tabSign === '0') {
			// 	params.payoutStatusList = [3, 5, 6]
			// }
			return this.getParams(params)
		},
		loadData() {
			const params = this.getSearchParams()
			this.tableData = []
			this.totalSummary = {}
			this.subSummary = {}
			const api =
				this.tabSign === '0'
					? 'getPlatformRecordList'
					: 'getOnlinePayWithdrawList'
			this.searchLoading = true
			this.$api[api](params)
				.then((res) => {
					const { record, totalRecord, summary } = res.data || {}
					record?.forEach((item) => {
						item.qukuanqianbao = Math.random() > 0.5 ? '1' : '0'
					})
					this.tableData = record || []
					this.total = totalRecord || 0
					this.totalSummary = summary || {}
					this.subSummary = summary || {}
					this.searchLoading = false
				})
				.catch(() => {
					this.searchLoading = false
				})
		},
		handleReset() {
			this.pageNum = 1
			this.queryData = {}
			this.loadData()
		},
		// 导出
		handleExport(queryData) {
			this.queryData = queryData
			const params = this.getSearchParams()
			delete params.pageNum
			delete params.pageSize
			this.exportLoading = true
			const exportApi =
				this.tabSign === '0'
					? 'getPlatformExport'
					: 'getFinanceWithdrawRecordExport'
			this.exportExcelPublic({
				api: exportApi,
				params
			}).finally(() => {
				this.exportLoading = false
			})
		},
		initData(activeTab) {
			this.topProxyTableHeight += 1
			this.nonTopProxyTableHeight += 1
			this.tabSign = activeTab.index
			this.setDefaultColSettings()
			this.handleSearch({})
		},
		setDefaultColSettings() {
			if (this.tabSign === '0') {
				this.activityListField = this.activityListTopField
				this.activeFiledName = 'platformDepositRecords'
			} else {
				this.activityListField = this.activityListNotTopField
				this.activeFiledName = 'platformWithdrawalRecords'
			}
			this.initIndexDB(this.activeFiledName, this.activityListField)
		},
		// 提交列设置数据
		handleColSettings() {
			this.colSettings.visible = false
			this.updateIndexDB()
			this.tabRandom = Math.random()
		},
		// 打开列设置弹框
		openColSettings() {
			this.getIndexDB(this.activityListField)
			this.colSettings.visible = true
		},
		// 列恢复设置
		clickDel() {
			const activityListColumn = {}
			if (this.tabSign === '0') {
				Object.keys(this.activityListTopField).forEach((item) => {
					activityListColumn[item] = true
				})
			} else {
				Object.keys(this.activityListNotTopField).forEach((item) => {
					activityListColumn[item] = true
				})
			}
			this.dialogColumnData = Object.assign({}, activityListColumn)
		}
	}
}
</script>

<style lang="scss" scoped>
::v-deep .el-table__fixed-footer-wrapper .cell,
::v-deep .el-table__footer-wrapper .cell {
	height: 100%;
	padding: 0 !important;
	margin: 0 !important;
	> div {
		height: 100%;
	}
}
::v-deep .footer_count_row {
	min-height: 50px;
	height: 50%;
	display: flex;
	font-weight: 700;
	padding: 5px 0;
	align-items: center;
	flex-direction: column;
	justify-content: center;
}
::v-deep .footer_count_row_border {
	border-top: 1px solid #ebeef5;
}
</style>
